﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using SelfService.Model.Models;


namespace SelfService.ViewModel.SysPatientLogVMs
{
    public partial class SysPatientLogListVM : BasePagedListVM<SysPatientLog_View, SysPatientLogSearcher>
    {

        protected override IEnumerable<IGridColumn<SysPatientLog_View>> InitGridHeader()
        {
            return new List<GridColumn<SysPatientLog_View>>{
                this.MakeGridHeader(x => x.Name_view),
                this.MakeGridHeader(x => x.IdCardNo),
                this.MakeGridHeader(x => x.Action),
                this.MakeGridHeader(x => x.Amount),
                this.MakeGridHeader(x => x.CreateTime),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysPatientLog_View> GetSearchQuery()
        {
            var query = DC.Set<SysPatientLog>()
                .CheckEqual(Searcher.PatientId, x=>x.PatientId)
                .CheckContain(Searcher.IdCardNo, x=>x.IdCardNo)
                .CheckContain(Searcher.Action, x=>x.Action)
                .CheckEqual(Searcher.Amount, x=>x.Amount)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .Select(x => new SysPatientLog_View
                {
				    ID = x.ID,
                    Name_view = x.Patient.Name,
                    IdCardNo = x.IdCardNo,
                    Action = x.Action,
                    Amount = x.Amount,
                    CreateTime = x.CreateTime,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysPatientLog_View : SysPatientLog{
        [Display(Name = "姓名")]
        public String Name_view { get; set; }

    }
}
